extends Control

onready var optBtn = $OptionButton

signal onSelect(tag)
signal onReset()

var choseList = []
onready var label = $Label
# Called when the node enters the scene tree for the first time.
func _ready():
	set_visible(false)
	pass # Replace with function body.

func setTagName(name):
	label.set_text(name)

func setItems(tagList,reInit = false):
	set_visible(true and not reInit)
	var index = optBtn.selected
	var oldTab 
	if index >= 0:
		oldTab = choseList[index]
	optBtn.clear()
	choseList = tagList.duplicate()
	choseList.push_front("全部")
	var leng = choseList.size()
	for id in range(leng):
		var tag = choseList[id]
		optBtn.add_item(tag,id)
	if reInit and oldTab :
		setChose(oldTab)
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#	pass
func setChose(tab):
	var index = choseList.find(tab)
	if index < 0 : 
		index = 0 
		emit_signal('onReset')
	optBtn.select(index)
	
	

func _on_OptionButton_item_selected(index):
	var tag = choseList[index]
	emit_signal('onSelect',tag)
